home *** CD-ROM | disk | FTP | other *** search
- From: tmdonahu@athena.mit.edu (Terence M Donahue)
- Subject: A faster sort
- Date: 7 Mar 89 19:36:58 GMT
-
- I was curious about all of these "better faster stronger" sorting
- programs, so I decided to try them out myself using a Vaxstation 2000
- running Unix.
-
- Functionality
- -------------
-
- The man page for sort(1) says that it merges all the
- files together and sorts the entire mess. Both fastsort and
- fastersort simply sort each file separately.
-
- In addition, fastsort produced different output from sort and
- fastersort, as reported by diff.
-
- Improvements
- ------------
-
- Use fputs() and putc() to output the sorted lines instead of fprintf()
-
- inline the strcmp function into compare().
-
- Ideally the compare() function should be built in to the qsort
- routine, eliminating the significant amount of procedure call
- overhead in the program. This was not done in fastestsort
- because my homemade quicksort is significantly slower than the
- qsort in the C library here. The qsort sources are not freely
- distributable. The inlining of the compare function would
- result in a significant speed improvement.
-
- Speed
- -----
-
- All programs were compiled with gcc with optimization on.
-
- termcap is the first 1000 lines of /etc/termcap, a file with long lines
- dict is the first 10000 lines of /usr/dict/words in reverse order, a
- file with short lines.
- All times are in seconds
-
- Method termcap dict
- ------ ------- ----
- sort 1.6u 0.5s 0:03 11.7u 0.4s 0:13
- fastsort 13.3u 1.2s 0:15 22.0u 1.9s 0:25
- fastersort 3.0u 0.2s 0:03 36.4u 0.4s 0:38
- fastestsort 1.2u 0.2s 0:01 13.1u 0.5s 0:14
-
- So good old sort beats out fastsort and fastersort. The latest version,
- fastestsort, does about as well as sort.
-
-
- Profiling
- ---------
-
- fastsort on termcap
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 65.3 9.05 9.05 1 9050.00 9522.34 _qst [4]
- 10.3 10.48 1.43 1 1430.00 11010.00 _qsort [3]
- 7.6 11.54 1.06 mcount (30)
- 5.8 12.34 0.80 2001 0.40 0.46 _fgets [5]
- 4.6 12.98 0.64 1007 0.64 0.68 __doprnt [7]
- 3.8 13.51 0.53 11095 0.05 0.05 _strcmp [8]
-
- fastsort on dict
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 39.4 10.20 10.20 mcount (25)
- 24.3 16.48 6.28 125441 0.05 0.05 _strcmp [5]
- 13.2 19.91 3.43 1 3430.00 9209.27 _qst [4]
- 10.2 22.54 2.63 10007 0.26 0.27 __doprnt [7]
- 4.8 23.77 1.23 20001 0.06 0.07 _fgets [8]
- 3.4 24.66 0.89 1 890.00 15690.00 _main [2]
-
- fastersort on termcap
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 35.7 1.27 1.27 mcount (21)
- 16.0 1.84 0.57 1000 0.57 0.62 __doprnt [7]
- 14.0 2.34 0.50 10900 0.05 0.05 _strcmp [8]
- 9.3 2.67 0.33 10900 0.03 0.08 _compare [5]
- 8.4 2.97 0.30 1 300.00 1037.79 _qst [4]
- 8.1 3.26 0.29 1 290.00 2290.00 _main [2]
-
- fastersort on dict
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 47.6 23.96 23.96 mcount (23)
- 21.0 34.54 10.58 218572 0.05 0.05 _strcmp [6]
- 12.5 40.83 6.29 218572 0.03 0.08 _compare [5]
- 9.9 45.82 4.99 1 4990.00 21027.27 _qst [4]
-
- fastestsort on termcap
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 27.1 0.61 0.61 mcount (22)
- 19.1 1.04 0.43 10900 0.04 0.04 _compare [5]
- 18.7 1.46 0.42 1 420.00 802.23 _qst [4]
- 10.7 1.70 0.24 1 240.00 1640.00 _main [2]
- 8.9 1.90 0.20 1 200.00 200.00 _read [6]
- 4.9 2.01 0.11 1000 0.11 0.17 _fputs [7]
- 4.0 2.10 0.09 6 15.00 15.00 _write [9]
- 2.2 2.15 0.05 2 25.00 25.00 _open [10]
- 2.2 2.20 0.05 1 50.00 900.00 _qsort [3]
-
- fastestsort on dict
- % cumulative self self total
- time seconds seconds calls ms/call ms/call name
- 44.9 12.34 12.34 mcount (21)
- 29.2 20.38 8.04 218572 0.04 0.04 _compare [5]
- 17.8 25.26 4.88 1 4880.00 12523.14 _qst [4]
- 2.8 26.02 0.76 1 760.00 15150.00 _main [2]
- 2.2 26.62 0.60 10000 0.06 0.07 _fputs [6]
- 1.0 26.89 0.27 1 270.00 13190.00 _qsort [3]
-